﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BolsaTrabajo.BusinessEntities;
using BolsaTrabajo.DataAccess;
using System.Transactions;
using System.Data;

namespace BolsaTrabajo.BusinessLogic
{
    public class UsersInRolesLogic
    {
        UsersInRolesData odata = null;

        public UsersInRolesLogic()
        {
            odata = new UsersInRolesData();
        }

        public Boolean Registrar(String userid, String roleid)
        {
            Boolean resultado = true;

            UsersInRoles BEUsersInRoles = new UsersInRoles();
            BEUsersInRoles.UserId = new Guid(userid);
            BEUsersInRoles.RoleId = new Guid(roleid);

            try
            {
                using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    resultado = odata.Registrar(BEUsersInRoles);
                    tx.Complete();
                }
            }
            catch (Exception)
            {
                resultado = false;
            }
            return resultado;
        }

        public Boolean Eliminar(UsersInRoles item)
        {
            Boolean resultado = true;
            try
            {
                using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    resultado = odata.Eliminar(item);
                    tx.Complete();
                }
            }
            catch (Exception)
            {

                resultado = false;
            }
            return resultado;
        }

        public List<UsersInRoles> ListarUsersInRolesPorUserName(String username)
        {
            List<UsersInRoles> resultado = new List<UsersInRoles>();
            try
            {
                using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    resultado = odata.ListarUsersInRolesPorUserName(username);
                    tx.Complete();
                }
            }
            catch (Exception)
            {

                throw;
            }
            return resultado;
        }
    }
}
